<template>
  <div class="nav-header">
    <div class="icon-box" @click="handleFoldClick">
      <template v-if="isFold">
        <el-icon :size="30" class="nav-icon"><Expand /></el-icon>
      </template>
      <template v-else>
        <el-icon :size="30" class="nav-icon"><Fold /></el-icon>
      </template>
    </div>
    <div class="url-word-box">
      <div class="out-word">
        <HyBreadcrumb :breadcrumbs="breadcrumbs" />
      </div>
      <div class="in-word">
        <NavHeader></NavHeader>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, computed } from "vue";
import { Expand, Fold } from "@element-plus/icons-vue";
import NavHeader from "./user-info.vue";
import HyBreadcrumb, { IBreadcrumb } from "@/base-ui/breadcrumb";

import { useStore } from "@/store";
import { useRoute } from "vue-router";
import { pathMapBreadcrumbs } from "@/utils/map-menus";

export default defineComponent({
  components: {
    Expand,
    Fold,
    NavHeader,
    HyBreadcrumb,
  },
  emits: ["foldChange"],
  setup(props, { emit }) {
    const isFold = ref(false);
    const handleFoldClick = () => {
      isFold.value = !isFold.value;
      emit("foldChange", isFold.value);
    };

    const store = useStore();
    const route = useRoute();
    const breadcrumbs = computed(() => {
      const userMenus = store.state.loginModule.userMenus;
      const currentPath = route.path;
      return pathMapBreadcrumbs(userMenus, currentPath);
    });

    return {
      isFold,
      handleFoldClick,
      breadcrumbs,
    };
  },
});
</script>

<style scoped lang="less">
.nav-header {
  display: flex;
  width: 100%;
  align-items: center;
  .icon-box {
    width: 30px;
    height: 30px;
  }
  .url-word-box {
    flex: 1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .out-word {
      padding-left: 10px;
    }
  }
}
</style>
